<?php

namespace App\Admin\Exports;

use App\Model\CoinLog;
use App\Model\User;
use App\Model\UserProfile;
use Encore\Admin\Grid\Exporters\ExcelExporter;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;

class UserProfileExport extends ExcelExporter implements WithMapping, WithHeadings, ShouldAutoSize
{
    protected $fileName = '用户资料.xlsx';
    public function headings(): array
    {
        return [
            '用户ID',
            '昵称',
            '角色',
            '最近上线时间',
            '状态',
            '手机'
        ];
    }

    public function map($data): array
    {
        return [
            $data->userProfile->user_profile_id,
            $data->userProfile->nick_name,
            $data->userProfile->role == UserProfile::ROLE_HOST ? '主播' : '普通用户',
            (string)$data->updated_at,
            User::STATUS[$data->status] ?? '未知',
            $data->phone,
        ];
    }
}
